﻿using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
using System;
namespace WPFExcelReport
{
    public partial class UIMSTOCK : ViewBase
    {
        public UIMSTOCK()
        {

        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
            FTAUTOSUM = true;
            TCOUNT1 = "行数";
            TKEY1 = "期初";
            SKEY1 = "LO";
            KEY1 = "BS00";
            TKEY2 = "期末";
            SKEY2 = "LO";
            KEY2 = "STOCKQTY";
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                KEY = "";
            }
            else
            {
                KEY = dwMaster["LO"].ToString().Trim().PadRight(2) + dwMaster["LB"].ToString().Trim().PadRight(2)
            + dwMaster["MDATE"].ToString().Trim().PadRight(8) + dwMaster["WAKZ"].ToString().Trim().PadRight(1) + dwMaster["ART"].ToString().Trim().PadRight(20)
            + dwMaster["VAR"].ToString().Trim().PadRight(2) + dwMaster["FARBE"].ToString().Trim().PadRight(10) + dwMaster["FINISH"].ToString().Trim().PadRight(10)
            + dwMaster["DESS"].ToString().Trim().PadRight(10)
            + dwMaster["COLORIT"].ToString().Trim().PadRight(10) + dwMaster["FSIZE"].ToString().Trim().PadRight(7) + dwMaster["FBPART"].ToString().Trim().PadRight(10) + dwMaster["SPPART"].ToString().Trim().PadRight(10)
            + dwMaster["ZWPART"].ToString().Trim().PadRight(10) + dwMaster["BEM1"].ToString().Trim().PadRight(40);

            }
        } 

      

        public virtual void OnSMOTHChg(string smoth)
        {
            if (MV == null)
                return;
            TMV.SMOTH = smoth;
            DTSTART = SYEAR + Helper.Right("00" + smoth, 2) + "21";
            MDATE = SYEAR + Helper.Right("00" + smoth, 2);
            if (smoth == "12")
            {
                DTEND = Convert.ToInt16(SYEAR) + 1 + "01" + "20";
            }
            else
            {
                DTEND = SYEAR + Helper.Right("00" + (Convert.ToInt16(SMOTH) + 1), 2) + "20";
            }
        }

        public override void OnDTSTARTChg(string value)
        {
            if (!value.EndsWith("21"))
            {
                IsNew = true;
                MessageBox.Show("不是21日开始，请手工进行更新操作");
            }
            base.OnDTSTARTChg(value);
        }

        public override void OnDTENDChg(string value)
        {
            if (!value.EndsWith("20"))
            {
                IsNew = true;
                MessageBox.Show("不是20日结束，请手工进行更新操作");
            }
            base.OnDTENDChg(value);
        }

 
    }
    public partial class UIMSTOCK : ViewBase
    {
        public VICC_STOCKM TMV
        {
            get
            {
                return (VICC_STOCKM)MV;
            }
        }
        #region ==dwKEY===========
        public static readonly DependencyProperty dwKEYProperty = DependencyProperty.Register("dwKEY",
            typeof(DataRowView), typeof(UIMSTOCK),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwKEYChanged));
        public DataRowView dwKEY
        {
            get
            {
                return (DataRowView)GetValue(dwKEYProperty);
            }
            set
            {
                SetValue(dwKEYProperty, value);
                OnMKEYChg(value);
            }
        }
        public virtual void OnMKEYChg(DataRowView dwMKey)
        {
        }
        private static void OndwKEYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMSTOCK;
            if (src != null)
            {
                src.dwKEY = (DataRowView)e.NewValue;
            }
        }
        #endregion

        #region ==SYEAR===========
        public static readonly DependencyProperty SYEARProperty = DependencyProperty.Register("SYEAR",
        typeof(string), typeof(UIMSTOCK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSYEARChanged));
        public string SYEAR
        {
            get
            {
                return (string)GetValue(SYEARProperty);
            }
            set
            {
                SetValue(SYEARProperty, value);
                OnSYEARChg(value);
            }
        }
        private static void OnSYEARChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMSTOCK;
            if (src != null)
            {
                src.SYEAR = (string)e.NewValue;
            }
        }
        public virtual void OnSYEARChg(string value)
        {
            if (MV == null)
                return;
            TMV.SYEAR = value;
        }
        #endregion
        #region ==SMOTH===========
        public static readonly DependencyProperty SMOTHProperty = DependencyProperty.Register("SMOTH",
        typeof(string), typeof(UIMSTOCK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSMOTHChanged));
        public string SMOTH
        {
            get
            {
                return (string)GetValue(SMOTHProperty);
            }
            set
            {
                SetValue(SMOTHProperty, value);
                OnSMOTHChg(value);
            }
        }
        private static void OnSMOTHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMSTOCK;
            if (src != null)
            {
                src.SMOTH = (string)e.NewValue;
            }
        }

        #endregion

        #region ==MDATE===========
        public static readonly DependencyProperty MDATEProperty = DependencyProperty.Register("MDATE",
        typeof(string), typeof(UIMSTOCK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMDATEChanged));
        public string MDATE
        {
            get
            {
                return (string)GetValue(MDATEProperty);
            }
            set
            {
                SetValue(MDATEProperty, value);
                OnMDATEChg(value);
            }
        }
        private static void OnMDATEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMSTOCK;
            if (src != null)
            {
                src.MDATE = (string)e.NewValue;
            }
        }
        public virtual void OnMDATEChg(string value)
        {
            if (MV == null)
                return;
            TMV.MDATE = value;
        }
        #endregion
    }
}
